#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
const int N = 2510, M = 6210 << 1;
int n, m, s, t;
int h[N], e[M], ne[M], w[M], idx;
int dist[N];
bool st[N];
void add(int a, int b, int c) {
  e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
void dijkstra() {
  memset(dist, 0x3f, sizeof(dist));
  memset(st, 0, sizeof st);
  priority_queue<pi, vector<pi>, greater<> > heap;
  heap.push({0, s});
  dist[s] = 0;
  while (!heap.empty()) {
    auto [d, u] = heap.top();
    heap.pop();
    st[u] = true;
    for (int i = h[u]; ~i; i = ne[i]) {
      int v = e[i];
      if (dist[v] > dist[u] + w[i]) {
        dist[v] = dist[u] + w[i];
        heap.push({dist[v], v});
      }
    }
  }
}
int main() {
  memset(h, -1, sizeof(h));
  cin >> n >> m >> s >> t;

  while (m--) {
    int a, b, c;
    cin >> a >> b >> c;
    add(a, b, c), add(b, a, c);
  }
  dijkstra();
  cout << dist[t] << endl;
  return 0;
}
